package com.qhy.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qhy.pojo.TbUser;
import com.qhy.pojo.ViewLet;
import com.qhy.service.ILetterService;

@Controller
@RequestMapping("let")
public class LetController {
	
	@Resource
	private ILetterService service;
	
	
	@RequestMapping("queryByUsId.do")
	public String queryByUsId(HttpServletRequest request,
			@RequestParam(defaultValue = "1")Integer tr1,@RequestParam(defaultValue = "1")Integer tr2) {
		TbUser user = (TbUser) request.getSession().getAttribute("login_user");
		PageHelper.startPage(tr1, 8);
		PageInfo<ViewLet> page1 = new PageInfo<ViewLet>(service.queryByRecId(user.getUsId()));
		request.setAttribute("p1", page1);
		PageHelper.startPage(tr2, 8);
		PageInfo<ViewLet> page2 = new PageInfo<ViewLet>(service.queryByRecIdAndStastu(user.getUsId()));
		request.setAttribute("p2", page2);
		return "user_letter";
	}
	
	
	@RequestMapping("readLet.do")
	public String readLet(Integer leId) {
		service.readLet(leId);
		return "forward:/let/queryByUsId.do";
	}
	
	@RequestMapping("deleteLet.do")
	public String deleteLet(Integer le_id) {
		service.deleteLet(le_id);
		return "forward:/let/queryByUsId.do";
	}
	
	
	
	
	
}
